package com.demo.project_template.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.project_template.entity.User;
import com.demo.project_template.entity.UserView;
import com.demo.project_template.mapper.UserMapper;
import com.demo.project_template.mapper.UserViewMapper;
import com.demo.project_template.service.UserViewService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户浏览用户表 服务实现类
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 11:48:58
 */
@Service
public class UserViewServiceImpl extends ServiceImpl<UserViewMapper, UserView> implements UserViewService {
    @Resource
    private UserMapper userMapper;

    @Override
    public Page<User> userFind(Integer pageNo, Integer pageSize, Long womanId) {
        Page<UserView> page = page(new Page<>(pageNo, pageSize), new LambdaQueryWrapper<UserView>().eq(UserView::getViewUserId, womanId));
        Page<User> userPage = new Page<>(page.getCurrent(),page.getSize(),page.getTotal());
        List<Long> userIds = page.getRecords().stream().map(UserView::getUserId).collect(Collectors.toList());
        return userPage.setRecords(userMapper.selectBatchIds(userIds));
    }
}
